<template>
  <div v-loading="loading">
    <el-row :gutter="10">
      <el-col :lg="7" :md="24">
        <el-card class="clusterPannel">
          <div class="row-bg">用户名称</div>
          <div class="contentcluster">
            <div>
              <el-input v-model.trim="searchInfo.ClusterName" @keyup.enter.native="queryUser('search')" size="small"
                placeholder="请输入用户名称" maxlength="100" style="width: 80%; margin-top: 20px;margin-left: 20px;">
                <i slot="prefix" class="el-input__icon el-icon-search"></i>
              </el-input>
            </div>
            <el-radio-group v-model="selRole" size="mini" v-if="userData.length>0">
              <el-radio @change.native="getUserInfo(item)" :label="item.id" border v-for="(item,index) in userData"
                :key="index">{{item.id}},{{item.name}}</el-radio>
            </el-radio-group>
            <div v-else style="text-align:center;margin-top:20px;">暂无数据</div>
            <el-pagination style="overflow:auto;text-align:center;" v-if="roleNameV.length>0"
              @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="currentPage"
              :page-sizes="[10, 20, 50,100]" :page-size="pageSize" layout="prev, pager, next" :total="tableTotal">
            </el-pagination>
          </div>
          <!-- <el-row>
            <el-col :span="12">
              <el-button type="primary" icon="el-icon-plus" size="mini" @click="openPop('addClu')">新建</el-button>
            </el-col>
            <el-col :span="12">
              <el-button type="primary" icon="el-icon-edit" size='mini' :disabled="!selRole"
                @click="openPop('editClu')">修改</el-button>
            </el-col>
            <el-col :span="12" style="margin-top:10px;">
              <el-button type="danger"  icon="el-icon-delete" size='mini' :disabled="!selRole" @click="openPop('delClu')">删除</el-button>
            </el-col>
          </el-row> -->
        </el-card>
      </el-col>
      <el-col :lg="17" :md="24">
        <el-card class="clusterPannel">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px">
            <div style="margin-bottom: 10px;">
              <i class="el-icon-edit"></i><span class="title">当前：新建用户</span>
            </div>
            <el-collapse v-model="activeNames" @change="handleChange">
              <el-collapse-item name="1">
                <template slot="title">
                  <i class="header-icon el-icon-user-solid" style="margin-right:4px;"></i>基本信息
                </template>
                <el-row :gutter="20" >
                  <el-col :lg="12" :md="24">
                    <el-form-item label="用户编号" prop="id">
                      <el-input v-model="ruleForm.id" size="small" placeholder="请输入用户编号"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :lg="12" :md="24">
                    <el-form-item label="用户姓名" prop="name">
                      <el-input v-model="ruleForm.name" size="small" placeholder="请输入用户姓名"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :lg="12" :md="24">
                    <el-form-item label="所属机构" prop="region">
                      <el-select v-model="ruleForm.region" placeholder="请选择所属机构" size="small">
                        <el-option label="1" value="shanghai"></el-option>
                        <el-option label="2" value="beijing"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :lg="12" :md="24">
                    <el-form-item label="用户状态" prop="status">
                      <el-select v-model="ruleForm.status" placeholder="请选择用户状态" size="small">
                        <el-option label="1" value="shanghai"></el-option>
                        <el-option label="2" value="beijing"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :lg="12" :md="24">
                    <el-form-item prop="startDate" label="生效时间">
                      <el-date-picker size="small" v-model="ruleForm.startDate" type="date" value-format="yyyyMMdd"
                        placeholder="开始日期" :picker-options="pickerOptionsStart" @change="changeStart">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :lg="12" :md="24">
                    <el-form-item prop="endDate" label="失效时间">
                      <el-date-picker size="small" v-model="ruleForm.endDate" type="date" value-format="yyyyMMdd"
                        placeholder="结束日期" :picker-options="pickerOptionsEnd" @change="changeEnd">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :lg="12" :md="24">
                    <el-form-item label="员工类型" prop="type">
                      <el-select v-model="ruleForm.type" placeholder="请选择员工类型" size="small">
                        <el-option label="1" value="shanghai"></el-option>
                        <el-option label="2" value="beijing"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :lg="12" :md="24">
                    <el-form-item label="用户等级" prop="level">
                      <el-select v-model="ruleForm.level" placeholder="请选择用户等级" size="small">
                        <el-option label="1" value="shanghai"></el-option>
                        <el-option label="2" value="beijing"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :lg="12" :md="24">
                    <el-form-item label="熟练度" prop="proficiency">
                      <el-select v-model="ruleForm.proficiency" placeholder="请选择熟练度" size="small">
                        <el-option label="1" value="shanghai"></el-option>
                        <el-option label="2" value="beijing"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :lg="12" :md="24">
                    <el-row>
                      <el-col :lg="12" :md="24">
                        <div class="chat">最大会话聊天数</div>
                      </el-col>
                      <el-col :lg="12" :md="24">
                        <el-form-item prop="chatNum" class="ml-125">
                          <el-input v-model="ruleForm.chatNum" size="small" placeholder="请输入最大会话聊天数"></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-col>
                </el-row>
              </el-collapse-item>
              <el-collapse-item name="2">
                <template slot="title">
                  <i class="header-icon el-icon-s-tools" style="margin-right:4px;"></i>技能
                </template>
                <el-row :gutter="20">
                  <el-col :lg="12" :md="24">
                    <el-form-item label="技能名称" prop="skillName">
                      <el-select v-model="ruleForm.skillName" placeholder="请选择技能名称" size="small">
                        <el-option label="技能1" value="shanghai"></el-option>
                        <el-option label="技能2" value="beijing"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :lg="12" :md="24">
                    <el-form-item prop="skillStartDate" label="生效时间">
                      <el-date-picker size="small" v-model="ruleForm.skillStartDate" type="date" value-format="yyyyMMdd"
                        placeholder="请选择技能生效日期" :picker-options="pickerOptionsStart" @change="changeStart">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :lg="12" :md="24">
                    <el-form-item prop="skillEndDate" label="失效时间">
                      <el-date-picker size="small" v-model="ruleForm.skillEndDate" type="date" value-format="yyyyMMdd"
                        placeholder="请选择技能失效日期" :picker-options="pickerOptionsEnd" @change="changeEnd">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row :gutter="20">
                  <el-col :lg="12" :md="24">
                    <el-form-item label="技能熟练" prop="skillDegree">
                      <!-- <el-select v-model="ruleForm.skillDegree" placeholder="请选择技能熟练度" size="small">
                        <el-option label="技能1" value="shanghai"></el-option>
                        <el-option label="技能2" value="beijing"></el-option>
                      </el-select> -->
                      <el-input-number v-model="ruleForm.skillDegree" size="small" :precision="2" :step="0.1" :max="10">
                      </el-input-number>
                    </el-form-item>
                  </el-col>
                  <el-col :lg="12" :md="24">
                    <el-row>
                      <el-col :span="12">
                        <div class="chat">技能优先级</div>
                      </el-col>
                      <el-col :lg="10" :md="24">
                        <el-form-item prop="chatNum" class="ml-140">
                          <el-input v-model="ruleForm.chatNum" size="small" placeholder="请输技能优先级"></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-col>
                </el-row>
              </el-collapse-item>
            </el-collapse>
            <el-row style="margin-left:300px;">
              <el-col>
                <el-form-item style="margin-top:10px;">
                  <el-button type="primary" size="small" @click="submitForm('ruleForm')">新建</el-button>
                  <el-button type="primary" size="small" @click="submitForm('ruleForm')">保存</el-button>
                  <el-button size="small" @click="resetForm('ruleForm')">重置</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  import request from "@/common/utils/requestWFM";
  import getGlobalParams from "@/common/utils/getGlobalParams";
  import userQuery from '@/message/wfm/baseData/userManage/userQuery'
  export default {
    name: "userManage",
    mounted (){
      // this.agentQuery()
    },
    data() {
      return {
        pickerOptionsStart: {
          disabledDate: (time) => {
            return time.getTime() < Date.now()
          }
        },
        pickerOptionsEnd: {
          disabledDate: (time) => {
            return time.getTime() < Date.now()
          }
        },
        activeNames: ['1', '2', '3', '4'],
        userData: [{
            id: '10000',
            name: '丁零'
          },
          {
            id: '10001',
            name: '丁一'
          },
          {
            id: '10002',
            name: '丁二'
          },
          {
            id: '10003',
            name: '丁三'
          },
          {
            id: '10004',
            name: '丁四'
          },
          {
            id: '10005',
            name: '丁五'
          },
          {
            id: '10006',
            name: '丁六'
          },
          {
            id: '10007',
            name: '丁七'
          },
          {
            id: '10008',
            name: '丁八'
          },
        ],
        branchNo: '',
        roleNameV: [],
        tips: [], //C端角色列表
        questionList: [],
        selRole: "", //当前选中得角色
        roleInfo: [], //当前角色的详细信息
        loading: false,
        PageFlag:'',
        currentPage: 1,
        pageSize: getGlobalParams.get("PageSize"),
        tableTotal: 0,
        PopType: '',
        addPopStatu: false,
        popTitle: '',
        searchInfo: {
          ClusterName: '',
        },
        ruleForm: {
          priority: '',
          skillDegree: '',
          skillEndDate: '',
          skillName: '', //技能名称
          proficiency: '', //熟练度
          chatNum: '', // 最大会话聊天数
          level: '', // 技能等级
          startDate: '', //生效日期
          endDate: '', // 结束日期
          No: '',
          id: '',
          name: '',
          status: '',
          media: '',
          type: '',
          level: ''
        },
        rules: {
          startDate: [{
            type: 'date',
            required: true,
            message: '请选择日期',
            trigger: 'change'
          }],
          endDate: [{
            type: 'date',
            required: true,
            message: '请选择日期',
            trigger: 'change'
          }],
          name: [{
              required: true,
              message: '请输入用户名称',
              trigger: 'blur'
            },
            {
              min: 3,
              max: 5,
              message: '长度在 3 到 5 个字符',
              trigger: 'blur'
            }
          ],
          id: [{
            required: true,
            message: '请输入用户编号',
            trigger: 'blur'
          }, ],
          No: [{
            required: true,
            message: '请输入所属法人行号',
            trigger: 'blur'
          }, ],
          region: [{
            required: true,
            message: '请选择活动区域',
            trigger: 'change'
          }],
          status: [{
            required: true,
            message: '请选择用户状态',
            trigger: 'change'
          }],
          type: [{
            required: true,
            message: '请选择员工类型',
            trigger: 'change'
          }],
          level: [{
            required: true,
            message: '请选择员工等级',
            trigger: 'change'
          }]
        }
      };
    },
    created() {
      // this.$nextTick(() => {
      //   this.queryClu();
      //   this.queryChannelType();
      // })
    },
    watch: {
      // addPopStatu(val,oldVal){
      //   if(!val){
      //     this.ClusterName = '';
      //     this.ClusterName2 = this.ClusterName3;
      //   }
      // }
    },
    methods: {
     async agentQuery() {
        let resBody = new userQuery()
        resBody.data.BRANCHNO = this.branchNo;
        resBody.data.CurrPage = this.currpage;
        resBody.data.PageRowNum = this.pageSize; 
        let response = await request(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          console.log(response.RSP_BODY)
          // this.tableData = response.RSP_BODY.RspStruct;
          // this.InTotalNum = response.RSP_BODY.TotalRowNum;
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      changeStart() {
        this.pickerOptionsEnd = Object.assign({}, this.pickerOptionsEnd, {
          disabledDate: (time) => {
            if (this.ruleForm.startDate) {
              return time.getTime() < Date.parse(this.ruleForm.startDate.slice(0, 4) + '-' + this.ruleForm
                .startDate.slice(4, 6) +
                '-' + this.ruleForm.startDate.slice(6, 8)) - 8.64e7 || time.getTime() < Date.now();
            } else {
              return time.getTime() < Date.now();
            }
          }
        })
      },
      changeEnd() {
        this.pickerOptionsStart = Object.assign({}, this.pickerOptionsStart, {
          disabledDate: (time) => {
            if (this.ruleForm.endDate) {
              return time.getTime() > Date.parse(this.ruleForm.endDate.slice(0, 4) + '-' + this.ruleForm.endDate
                .slice(4, 6) + '-' +
                this.ruleForm.endDate.slice(6, 8)) || time.getTime() < Date.now();
            } else {
              return time.getTime() < Date.now();
            }
          }
        })
      },
      handleChange(val) {
        console.log(val);
      },
      getUserInfo(item) {
        console.log(item)
      },
      //查询簇列表
      queryUser(data) {
        // if(data){
        //   this.currentPage = 1;
        // }
        // this.loading = true;
        // let resBody1 = new ClusterQuery();
        // resBody1.data.ClusterId = "";
        // resBody1.data.ClusterName = this.searchInfo.ClusterName;
        // resBody1.data.PageFlag = '4';
        // resBody1.data.CurrPage = this.currentPage + "";
        // resBody1.data.PageRowNum = this.pageSize + "";
        // request(resBody1)
        //   .then(response => {
        //     if (response.SYS_HEAD.ReturnCode === "000000") {
        //       this.loading = false;
        //       this.roleNameV = response.RSP_BODY.RspStruct;
        //       this.tableTotal = response.RSP_BODY.TotalRowNum;
        //       this.NowPageNum= response.RSP_BODY.NowPageNum;
        //     } else {
        //       this.loading = false;
        //       this.$message({
        //         type: "error",
        //         message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
        //       });
        //     }
        //   })
        //   .catch(error => {
        //     this.loading = false;
        //     console.log(error);
        //   });
      },
      handleSizeChange(val) {
        this.pageSize = val;
        this.queryUser();
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.queryUser();
      },
      // // 删除弹出信息
      // delRoleClick(data,msg) {//删除弹出
      //   this.$confirm(`此操作将删除该${msg}, 是否继续?`, "提示", {
      //     confirmButtonText: "确定",
      //     cancelButtonText: "取消",
      //     type: "warning"
      //   })
      //     .then(() => {
      //       if(this.PopType == 'delClu'){
      //         this.delCluster();
      //       }else if(this.PopType == 'delCluAndTips'){
      //         this.delCluAndTips(data);
      //       }else if(this.PopType == 'delCluAndKnow'){
      //         this.delCluAndKnow(data);
      //       }else{
      //         console.log('error');
      //       }
      //     })
      //     .catch(() => {
      //       this.$message({
      //         type: "info",
      //         message: "已取消删除"
      //       });
      //     });
      // },
      // // 删除簇信息
      // delCluster() { 
      //   this.loading = true;
      //   let resBody = new delCluster();
      //   resBody.data.ClusterId = this.selRole;
      //   request(resBody)
      //     .then(response => {
      //       if (response.SYS_HEAD.ReturnCode === "000000") {
      //         this.loading = false;
      //         this.$message({
      //           type: "success",
      //           message: "删除成功!"
      //         });
      //         this.queryUser();
      //         this.queryUser();
      //       } else {
      //         this.loading = false;
      //         this.$message({
      //           type: "error",
      //           message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
      //         });
      //       }
      //     })
      //     .catch(error => {
      //       this.loading = false;
      //       this.$message({
      //         type: "info",
      //         message: error
      //       });
      //     });
      // },
      // 簇弹窗修改编辑
      submitForm() {
        if (this.PopType == 'addClu') {
          if (!this.ClusterName) {
            this.$message({
              message: '请先输入簇名称',
              type: "error  "
            });
            return;
          }
          // 添加簇  
          this.addClu();
        } else if (this.PopType == 'editClu') {
          if (!this.ClusterName2) {
            this.$message({
              message: '请先输入簇名称',
              type: "error  "
            });
            return;
          }
          // 编辑簇
          this.editClu();
        } else {
          console.log("submitForm 出错啦");
        }
      },
      // 添加簇名称
      addClu() {
        this.loading = true;
        let resBody = new addCluster();
        resBody.data.ClusterName = this.ClusterName;
        request(resBody)
          .then(response => {
            if (response.SYS_HEAD.ReturnCode === "000000") {
              this.loading = false;
              this.addPopStatu = false;
              this.queryUser();
              //将后台的枚举值存入
              this.$message({
                message: '添加成功',
                type: "success"
              });
            } else {
              this.$message({
                message: response.SYS_HEAD.ReturnMessage,
                type: "error  "
              });
              this.loading = false;
              this.addPopStatu = false;
            }
          })
          .catch(error => {
            this.loading = false;
            this.addPopStatu = false;
            console.log("error", error);
          });
      }
    }
  };

</script>


<style lang="scss" scoped>
  .title{
    margin-left: 6px;
    font-size: 15px;
    color: #409EFF;
  }
  .chat {
    color: #606266;
    margin-left: 10px;
    // text-align: right;
    vertical-align: middle;
    font-size: 14px;
    line-height: 40px;
    padding: 0 12px 0 0;
  }

  .ml-125 {
    margin-left: -125px !important;
  }

  .ml-140 {
    margin-left: -140px !important;
  }


  .wrap {
    width: 85%;
    word-wrap: break-word;
    display: inline-block;
    vertical-align: text-top;
  }

  .headercluser {
    padding: 10px 10px;
    background: #f5f7fa;
    border-bottom: 1px solid #e4e7ed;
  }

  .cluserBox {
    height: 555px;
    overflow-y: auto;
    padding: 10px;
  }

  .cluserBox::-webkit-scrollbar {
    display: none;
  }

  .clusterPannel {
    min-height: 710px;
  }

  .contentcluster {
    width: 100%;
    height: 540px;
    border: 1px solid #eee;
    border-radius: 3px;
    margin: 10px 0;
    overflow-y: auto;
  }

  .contentcluster::-webkit-scrollbar {
    display: none;
  }

  .el-radio-group {
    padding: 10px;
  }

  .el-radio:first-child {
    margin-left: 10px;
  }

  .el-radio {
    display: inline-block;
    margin: 10px;
    width: 135px;
    display: flex;
    height: auto;
    padding: 6px 15px 6px 10px;
    white-space: inherit;
  }

  .cluserBlock {
    border: 1px solid #eee;
    margin-right: 10px;
    border-radius: 3px;
    height: 638px;
    /* overflow: auto; */
  }

  .el-card {
    margin-bottom: 10px;
    width: 100%;
  }

  .row-bg {
    padding: 10px 10px;
    background: #f5f7fa;
    margin: 0 auto;
  }

  .box-card {
    width: 100%;
    margin-bottom: 5px;
  }

  .box-card:hover {
    background: rgba(64, 158, 255, 0.4);
  }

  ol>li {
    padding-bottom: 20px;

    .el-button--text {
      padding: 0;
    }
  }

</style>
